import sys
import click

from core.install import InstallVerify


@click.command("initrepo", help="更新repo源文件")
@click.option(
    "-a",
    "--arch",
    help="软件架构",
    type=click.Choice(["x86_64", "aarch64"], case_sensitive=False),
    default="x86_64",
    show_default=True,
    required=True,
)
@click.option("-tb", "--target-branch", help="pr的目标分支")
def init_repo(arch, target_branch):
    click.echo("[INFO] start check build")
    install_obj = InstallVerify(arch, target_branch)
    result = install_obj.update_repo(target_branch)
    if result:
        click.echo(click.style("Failed to update repo source", fg="red"))
        sys.exit(1)
    else:
        click.echo(click.style("Update repo source successful", fg="green"))


__all__ = "init_repo"
